<?php

/*
CSS Klassen

modNewsletter_topcell - Error anzeige
modNewsletter_cell - Text
modNewsletter_textfield - Textfeld
modNewsletter_submitbutton - Submitbutton
modNewsletter_bottomcell - Submitbutton-Zelle
modNewsletter_thx - "Sie haben den NL nun aboniert"-Text

*/
include_once($cfgPaths['mod'].'mod_newsletter/lib/dbaNewsletter.o.inc.php');
$modNLdba = new dbaNewsletter($udba);

$eMailError = false;
if ($env->getPost('action') == 'addEmail')
{
    if (preg_match("/^[\w\d][\w\d_\.]+[\w\d]@([\w\d][\w\d\-]+[\w\d]\.)+\w{2,4}$/i",$env->param('email')))
    {
        $modNLdba->addEntry($params['instance'], $env->param('name'), $env->param('email'), 
            $env->param('cellphone'));
        $errorNo = $udba->getErrorNo();
        if ($errorNo)
        {
            $eMailError = true;
            switch ($errorNo)
            {
                case '1062':
                    $errorMsg = "Es existiert schon ein Eintrag mit dieser eMail-Adresse!";
                    break;
            }
        }
    }
    else
    {
        $eMailError = true;
        $errorMsg = "keine valide eMail-Adresse";
    }
}

if (($env->param('action') != 'addEmail') || $eMailError == true):
?>
  <table border="0" class="modNewsletter_table" cellspacing="0">
  <form action="<?php echo $env->getServer('SCRIPT_NAME') ?>" method="post">
  <input type="hidden" name="action" value="addEmail"/>
<?php
if ($eMailError)
{
?>
    <tr>
        <td class="modNewsletter_topcell" colspan="2"><?php echo $errorMsg ?></td>
    </tr>
<?php
}
?>
    <tr>
        <td class="modNewsletter_cell">Name:</td>
        <td class="modNewsletter_cell"><input class="modNewsletter_textfield" type="text" name="name" value="<?php 
                    echo $env->param('name')
                 ?>" size="30" maxlength="255"/></td>
    </tr>
    <tr>
        <td class="modNewsletter_cell">eMail:</td>
        <td class="modNewsletter_cell"><input class="modNewsletter_textfield" type="text" name="email" value="<?php 
                    echo $env->param('email')
                 ?>" size="30" maxlength="255"/></td>
    </tr>
    <tr>
        <td class="modNewsletter_cell">Mobil/Tel:</td>
        <td class="modNewsletter_cell"><input class="modNewsletter_textfield" type="text" name="cellphone" value="<?php 
                    echo $env->param('cellphone')
                 ?>" size="30" maxlength="255"/></td>
    </tr>
    <tr>
        <td class="modNewsletter_bottomcell" colspan="2"><input class="modNewsletter_submitbutton" type="submit" value="Eintragen"/></td>
    </tr>
  </form>
  </table>
<?php
else:
print "<p class=\"modNewsletter_thx\">Sie haben den Newsletter nun aboniert!</p>";
endif;
?>